// import calculator from '../product/productdetail.js';

require(['../config'], function () {
	require(['jquery', 'avalon', 'util', 'loan/product-apply', 'Cookies', 'text!/common/nav.html', 'text!/common/footer.html', 'navInit'], function ($, avalon, util, productApply, Cookies,
		navHtml,
		footerHtml,
		navInit) {
		$(".global-nav").html(navHtml);
		$(".global-footer").html(footerHtml);
		navInit();

		var productId = util.getUrlParam('productId');

		var vm = avalon.define({
			$id: 'channel-list',
			data: {},
			productId: productId,
			pageItems: [1, 2, 3, 4, 5],
			params: {
				page: 0,
				limit: 1
			},
			imgUrl: function (item) {
				return item.logo || '/assets/images/product/channel.png';
			},
			star: function (score) {
				var list = [];
				for (var i = score || 5; i--;) {
					list.push('<i class="iconfont icon-star"></i>');
				}
				return list.join('');
			},
			search: function () {
				var data = vm.$model;
				util.ajax({
					url: '/loan/product/' + productId + '/manager/list',
					type: 'post',
					data: data.params,
					success: function (rsp) {
						$('.content-wrap').show();
						vm.data = rsp.data;
						vm.pageItems = util.getPageItems(rsp.data.pageNum, rsp.data.total, rsp.data.pages);
					}
				});
			},
			changePage: function (p) {
				this.params.page = p;
				this.search()
			},
			apply: function (managerId, productId) {
				productApply.apply(managerId, productId);
			}
		});

		avalon.scan(document.body);

		$(function () {
			vm.search();
		})
	})
});